package top.zackyoung.thirdlogin.controller;

import cn.hutool.http.HttpRequest;
import lombok.SneakyThrows;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import top.zackyoung.thirdlogin.enums.LoginType;
import top.zackyoung.thirdlogin.factory.FactoryForLogin;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ZackYoung
 * @version 1.0
 * @description
 * @date 2021/6/5 22:58
 */
@Controller
public class LoginController {
    @Resource
    FactoryForLogin factoryForLogin;


    @SneakyThrows
    @RequestMapping("/login/{loginType}")
    public String login(@PathVariable LoginType loginType, HttpServletResponse resp) {
        String login = factoryForLogin.getLogin(loginType.getName()).login();
        return  "redirect:" + login;
    }
    @SneakyThrows
    @RequestMapping("/callback/{loginType}")
    @ResponseBody
    public String callback(@PathVariable LoginType loginType, String state,String code) {
        String callback = factoryForLogin.getLogin(loginType.getName()).callback(state, code);
        return  callback;
    }
}
